package com.itheima.JDBC;

import java.sql.*;
import java.util.ArrayList;

public class demo01 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1.获取驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //2.获取链接
        String url = "jdbc:mysql://127.0.0.1:3306/db01";
        String username = "root";
        String password = "328802";
        Connection connection = DriverManager.getConnection(url, username, password);
        String sql = "select * from account";
        Statement statement = connection.createStatement();
        ResultSet rs = statement.executeQuery(sql);
        ArrayList<Acccount> ats = new ArrayList<>();
        while (rs.next()) {
            int id = rs.getInt(1);
            String name = rs.getString(2);
            double money = rs.getDouble(3);
            Acccount acccount = new Acccount(id, name, money);
            ats.add(acccount);
            System.out.println(id + ":" + name + ":" + money);
        }
        for (int i = 0; i < ats.size(); i++) {
            Acccount a = ats.get(i);
            System.out.println(a.getId()+a.getName()+a.getMoney());
        }
        statement.close();
        connection.close();
    }
}
